package com.example.echoewish.ui.my_activity.other_comment_activity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.echoewish.pojo.OthersComment;
import com.example.echoewish.R;

import java.util.List;

public class OthersCommentAdapter extends ArrayAdapter<OthersComment> {
    private TextView othersCommentTitleTextView;
    private TextView othersCommentContentTextView;
    private TextView othersCommentTimeTextView;
    private Button othersCommentButton;

    private int resource;
    private Context context;

    private ButtonClickListener buttonClickListener;

    public OthersCommentAdapter(@NonNull Context context, int resource, @NonNull List<OthersComment> objects) {
        super(context, resource, objects);
        this.context=context;
        this.resource=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view= LayoutInflater.from(context).inflate(resource,parent,false);
        othersCommentTitleTextView=view.findViewById(R.id.others_comment_title_text_view);
        othersCommentContentTextView=view.findViewById(R.id.others_comment_content_text_view);
        othersCommentTimeTextView=view.findViewById(R.id.others_comment_time_text_view);
        othersCommentButton=view.findViewById(R.id.others_comment_delete_button);

        OthersComment othersComment=getItem(position);
        if(othersComment!=null)
        {
            othersCommentTitleTextView.setText(othersComment.user.name+"给你帖子留言");
            othersCommentContentTextView.setText(othersComment.content);
            othersCommentTimeTextView.setText(othersComment.time);
        }
        othersCommentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                buttonClickListener.buttonClickListener(position);
            }
        });
        return view;
    }

    public void setButtonClickListener(ButtonClickListener buttonClickListener){
        this.buttonClickListener=buttonClickListener;
    }

    public interface ButtonClickListener
    {
        void buttonClickListener(int nowPosition);
    }
}
